package com.miaoshaproject;

import com.miaoshaproject.dao.UserDOMapper;
import com.miaoshaproject.dataobject.UserDO;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Hello world!
 *
 */
//让springboot扫描mybatis的配置文件、生成文件
@SpringBootApplication(scanBasePackages = {"com.miaoshaproject"})//让所对应的这些类被springboot托管，并指定该类是主启动类
@RestController
@MapperScan("com.miaoshaproject.dao")//dao类存放的地方
public class App {
    //测试一下，看UserDO类里是否有对象
    @Resource
    private UserDOMapper userDOMapper;//UserDOMapper类里有增、删、改、查的方法，用来增、删、改、查
    @RequestMapping("/")
    public String home(){
        UserDO userD0= userDOMapper.selectByPrimaryKey(1);//通过UserDOMapper的对象调用查询方法
        if(userD0==null){
            return "用户对象不存在";
        }else{
            return userD0.getName();
        }
    }


    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        SpringApplication.run(App.class,args);
    }
}
